
import request from '../request';

interface AdminLoginParmas {
    password: string,
    username: string
}

interface AdminLoginResData{
    token: string,
    tokenHead :string
}

interface AdminInfoResData{
    menus: MenusType[];
}

interface AdminListParmas{
    pageNum: number;
    keyword: string;
    pageSize: number;
}

interface AdminListResData{
    list: {}[];
    total: number;
}

interface RoleUpdateParmas{
    adminId: number;
    roleIds: string;
}


// 登录接口
export const adminLogin = (data: AdminLoginParmas): PromiseRes<AdminLoginResData> => request.post("/admin/login", data);

// 获取当前的登录用户信息
export const getAdminInfo = (): PromiseRes<AdminInfoResData> => request.get('/admin/info'); 

// 获取用户列表
export const getAdminList = (data: Partial<AdminListParmas>): PromiseRes<AdminListResData> => request.get('/admin/list', { params: data });

// 修改指定用户信息
export const updateAdmin = (id: number, data: AdminResDataObj): PromiseRes<unknown> => request.post('/admin/role' + data.id, data);

// 用户注册
export const registerAdmin = (data: AdminResDataObj): PromiseRes<unknown> => request.post('/admin/register', data);

// 获取指定用户的角色列表
export const getAdminRoleById = (id: number): PromiseRes<{ id: number }[]> => request.get("/admin/role/" + id);

// 给用户分配角色
export const updateAdminRole = (data:RoleUpdateParmas):PromiseRes<unknown> =>request.post("/admin/role/update",null,{params:data})